package com.xzmzhp.dao.power;

import com.xzmzhp.dao.power.SQL.RequestPathSQL;
import com.xzmzhp.pojo.power.Competence;
import com.xzmzhp.pojo.power.RequestPath;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 王源(xm)
 * @Date: 2020/12/8 23:36
 * @Description: 请求路径操作类
 */
@Repository
public interface RequestPathMapper {

    /**
     * 查询所有请求路径
     *
     * @return 请求路径集合
     */
    @Select("select id,url,description from request_path")
    List<RequestPath> findAll();

    /**
     * 查询所有请求路径
     *
     * @return 请求路径集合
     */
    @Select("select url from request_path")
    List<String> findAllRequestPath();

    /**
     * 根据请求路径模糊查询
     *
     * @param url 请求路径
     * @return 请求路径集合
     */
    @Select("select id,url,description from request_path where url like '%${url}%'")
    List<RequestPath> findByUrl(@Param("url") String url);

    /**
     * 根据请求路径查询所对应的权限
     *
     * @param id 请求路径id
     * @return 权限集合
     */
    @Select("select competence.competence_id,competence.competence_name FROM competence,menu_request,competence_menu " +
            "WHERE menu_request.menu_id = competence_menu.menu_id and competence_menu.competence_id = competence.competence_id AND menu_request.id =#{id}")
    List<Competence> findByOneUrl(@Param("id") Integer id);

    /**
     * 根据请求路id查询
     *
     * @param id 请求路径id
     * @return 请求路径集合
     */
    @Select("select id,url,description from request_path where id = #{id}")
    RequestPath findById(@Param("id") Integer id);

    /**
     * 批量插入所有请求路径
     *
     * @param list 请求路径
     * @return 是否成功集合
     */
    @InsertProvider(type = RequestPathSQL.class, method = "addRequestPaths")
    Integer addRequestPaths(@Param("list") List<RequestPath> list);

    /**
     * 修改请求路径
     *
     * @param requestPath 请求路径集合
     * @return 是否成功
     */
    @UpdateProvider(type = RequestPathSQL.class, method = "updateRequestPath")
    Integer updateRequestPath(@Param("requestPath") RequestPath requestPath);

    /**
     * 删除请求路径
     *
     * @param id 请求路径id
     * @return 是否成功
     */
    @Delete("delete from request_path where id = #{id}")
    Integer deleteRequestPath(@Param("id") Integer id);
}
